package org.batatasframework.support.database.values;

import java.sql.ResultSet;
import java.util.List;

import org.batatasframework.support.database.sql.field.FieldElement;
import org.batatasframework.support.database.sql.field.SelectFragment;


public abstract class AbstractMultipleValueHolder extends AbstractValueHolder{
	protected final List<? extends FieldElement> relations;
	
	public AbstractMultipleValueHolder(SelectFragment field, List<? extends FieldElement> relations){
		super(field);
		this.relations = relations;
	}

	@Override
	public FieldValue read(ResultSet rs) throws Exception {
		Object[] args = new Object[relations.size()];
		int i = 0;
		for(FieldElement fr : relations){
			args[i++] = rs.getObject(fr.getAlias());
		}
		return read(args);
	}

	protected abstract FieldValue read(Object[] args) throws Exception;
}
